<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="线索论坛"></uni-navbar></view>

		<!-- <u-tabs class="tabs" :list="list" :is-scroll="false" :current="filterType" @change="change"></u-tabs> -->
		<view class="tab_list">
			<view class="tab_view" v-for="(item, index) in issueList" :key="index">
				<view class="a_con" @click="navTo('/pagesA/forum/detail?id=' + item.id)">
					<view class="a_con_status">
						<image class="status_img" :src="$imagePreview(item.touxiang)" mode="aspectFill"></image>
						<text class="status_name">{{ item.createByName }}</text>
						<!-- 	<text class="status_lb">{{ item.jiebie }}</text> -->
					</view>

					<block v-if="item.fileList.length > 0">
						<view class="list_img" v-for="(item2, index2) in item.fileList.slice(0, 3)" :key="index2">
							<image class="image" :src="baseUrl + '/file/download/preview/0?path=' + item2.path" mode="aspectFill"></image>
						</view>
					</block>

					<view class="a_con_tit" style="border-bottom: 2rpx solid #f1f2f3">{{ $htmlRegx(item.content) }}</view>
				</view>
				<view class="a_tlz" @click="navTo('/pagesA/forum/detail?id=' + item.id)" style="padding-top: 10px">
					<view class="a_tlz_p">
						<!-- <text class="a_tlz_name">{{ item.groupName }}</text> -->
						<text class="a_tlz_time">{{ item.createTime | parseTime('{y}-{m}-{d}') }}</text>

						<text class="a_tlz1">评论:{{ item.readNum }}</text>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>

		<view class="uploader-add" @click="navTo('/pagesA/forum/add')"><u-icon name="plus" color="#fff" size="40"></u-icon></view>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import * as config from '@/config';
export default {
	data() {
		return {
			baseUrl: config.def().baseUrl,
			scrollTop: 0,
			list: [
				{
					name: '线索论坛'
				},
				{
					name: '我的讨论组'
				}
			],
			colorMap: {
				1: '#303133',
				2: '#0099ff',
				3: '#ff9900',
				9: '#19be6b'
			},
			filterType: 0,
			keyword: '',
			issueList: [],
			groupList: [],
			pageNum: 1,
			pageSize: 10,
			wlyzIssue: {
				groupName: '',
				status: 1
			},
			wlyzGroup: {
				groupName: '',
				status: 1
			},
			clientCode: '',
			roleCodes: '',
			currentUserId: '',
			loading: 'loadmore'
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadData('refresh');
	},
	onPullDownRefresh() {
		this.loadLogin();
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		change(e) {
			this.filterType = e;
			this.pageNum = 1;
			this.loadData('refresh');
		},
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.currentUserId = this.userInfo.sysUser.id;
				this.roleCodes = this.userInfo.roleCodes.join(',');
				this.userName = this.userInfo.sysUser.userName;
			} else {
				this.$store.commit('logout');
				this.$msg('请先登录');
				setTimeout(() => {
					uni.navigateTo({
						url: '/pages/login/login'
					});
				}, 500);
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}

			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				currentUserId: this.currentUserId
			};

			//data.wlyzIssue = this.wlyzIssue;
			this.$request('/sqmybbs/list', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					this.issueList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.issueList = this.issueList.concat(res.data.records);
				this.loaded = true;
				if (this.issueList.length <= 0) {
					this.loading = 'nodata';
				}
				if (type != 'add') {
					uni.stopPullDownRefresh();
				}
			});
		},
		search(e) {
			this.keyword = e;
			this.loadData('refresh');
		},
		type(e) {
			this.filterType = e;
			this.loadData('refresh');
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>

<style lang="scss">
.list_img {
	width: 220rpx;
	height: 148rpx;
	display: inline-block;
	margin: 0 5rpx;

	.image {
		width: 200rpx;
		height: 148rpx;
	}
}

.list-box {
	margin-bottom: 30rpx;
	padding: 30rpx 30rpx 0;
	border-radius: 30rpx;
	background-color: #fff;
}

.tabs {
	position: absolute;
	left: 0;
	right: 0;
	border-bottom: 1rpx solid #f1f2f3;
}

.tab_list {
	//padding-top: 80rpx;
	width: 100%;
	height: auto;

	.tab_view {
		width: 100%;
		padding: 34rpx 30rpx 26rpx;
		line-height: 1.4;
		border-bottom: 20rpx solid #f1f2f3;
		background-color: #fff;

		.a_con {
			color: #333333;

			.a_con_tit {
				padding: 36rpx 0;
				width: 100%;
				font-size: 18px;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
			}

			.a_con_status {
				display: flex;
				align-items: center;
				margin: 14rpx 0 18rpx;
				width: 100%;
				font-size: 14px;
				color: #999;
				line-height: 50rpx;

				.status_img {
					flex-shrink: 0;
					width: 50rpx;
					height: 50rpx;
					border-radius: 50%;
					overflow: hidden;
					background-color: #f1f2f3;
				}

				.status_name {
					flex-shrink: 0;
					margin: 0 12rpx;
					font-size: 14px;
				}

				.status_lb {
					margin: 0 8rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					/* position: relative;
					top: 0.3rem; */
				}

				.status_node {
					flex-shrink: 0;
					margin-left: auto;
					padding: 8rpx 20rpx;
					font-size: 13px;
					line-height: 1;
				}
			}

			.a_con_content {
				display: none;
				width: 100%;
				font-size: 14px;
				color: #333333;
			}
		}

		.a_tlz1 {
			display: inline-block;
			float: right;
			text-align: right;
		}

		.a_tlz {
			color: #999;
			/* text-align: right; */

			.a_tlz_p {
				font-size: 13px;

				.a_tlz_name {
					display: inline-block;
					margin-right: 40rpx;
				}
			}
		}

		.a_group {
			display: flex;
			align-items: center;
			/* padding: 0 15rpx; */
			font-size: 16px;

			.a_img {
				display: flex;
				align-items: center;
				justify-content: center;
				flex-shrink: 0;
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				text-align: center;
				font-size: 14px;
				color: #fff;
				line-height: 1.2;
				background: #f90;

				image {
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
				}
			}

			.a_name {
				padding-left: 26rpx;
				line-height: 1.2;
			}
		}
	}
}

.st_end {
	color: #999;
	border: 1rpx solid #999;
	border-radius: 10rpx;
}

.st_tlz {
	color: #e5231a;
	border: 1rpx solid #e5231a;
	border-radius: 10rpx;
}

.st_gly {
	margin-right: 10rpx;
	color: #e5231a;
	border: 1rpx solid #e5231a;
	border-radius: 10rpx;
}
</style>
